# coding = utf-8
import numpy as np
import cv2 as cv
import matplotlib.pyplot as plt

# 导入资源
image = cv.imread("D:\\data\\real\\IMG_5469.JPG")
image_copy = np.copy(image)
image_copy = cv.cvtColor(image_copy, cv.COLOR_BGR2RGB)
img_gray = cv.cvtColor(image_copy, cv.COLOR_RGB2GRAY)
gray = np.float32(img_gray)

# 检测角点
dst = cv.cornerHarris(gray, 2, 3, 0.04)
dst = cv.dilate(dst, None)

# 提取并显示强角点
thresh = 0.1*dst.max()
#corner_image = np.copy(image_copy)
corner_image = cv.cvtColor(img_gray, cv.COLOR_GRAY2RGB)

for j in range(0, dst.shape[0]):
    for i in range(0, dst.shape[1]):
        if(dst[j,i] > thresh):
            # image, center pt, radius, color, thickness
            cv.circle(corner_image, (i, j), 10, (0,255,0), 2)
cv.imwrite('Harris.jpg', corner_image)
plt.imshow(corner_image)
plt.show()